package com.wyzy.spring.project;

import jakarta.servlet.http.HttpSession;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/login")
@RestController
public class login {
    @PostMapping("/login")
    public Boolean login(String userName, String password, HttpSession session){
        if(!StringUtils.hasLength(userName) || !StringUtils.hasLength(password)){
            return false;
        }
        //TODO 从数据库中获取账号密码
        if(!"admin".equals(userName) || !"admin".equals(password)){
            return false;
        }
        session.setAttribute("userName","admit");
        return true;
    }
    @GetMapping("/getUserName")
    public String getUserName (HttpSession session){
        String userName = (String)session.getAttribute("userName");
        if(StringUtils.hasLength(userName)){
            return userName;
        }
        return "";
    }
}
